package org.blade.personal.dao.sys.impl;

import java.util.List;
import java.util.Map;

import org.blade.personal.dao.base.BaseDao2;
import org.blade.personal.dao.sys.SystemRefAuthorityDao;
import org.blade.personal.mode.sys.SystemRefAuthority;
import org.blade.personal.utils.Pager;
import org.springframework.stereotype.Repository;

@Repository("systemRefAuthorityDao")
public class SystemRefAuthorityDaoImpl extends BaseDao2<SystemRefAuthority,Long> implements SystemRefAuthorityDao {

	@Override
	public void add(SystemRefAuthority t) {
		
		super.add(t);
	}

	@Override
	public void update(SystemRefAuthority t) {
		super.update(t);

	}

	@Override
	public int delete(String ids) {
		return super.delete("delete * from sys_ref_authority where id in (?)", ids);
	}

	@Override
	public void pagingQuery(Pager<SystemRefAuthority> page,
			Map<String, Object> params) {
		
	}

	@Override
	public SystemRefAuthority getOne(Map<String, Object> map) {
		// TODO Auto-generated method stub
		return null;
	}
 
	@Override
	public List<SystemRefAuthority> getByRefId(Long id, Integer type) {

		String querySql = " select * from sys_ref_authority where ref_id = ?  and refType = ? ";
		return this.queryForList(querySql, new Object[]{ id, type} );
	}

	
	@Override
	public List<SystemRefAuthority> getAll() {
		return this.findList();
	}
	
	@Override
	public int delete(int refType, int refId, Long authorityId) {
		String deleteSql = " delete  from SystemRefAuthority sra  where 1=1 and  sra.refType = ?  and sra.refId = ? and  sra.sysAuthorityId = ?";
		return super.entityManager.createNativeQuery(deleteSql)
		.setParameter(1, refType)
		.setParameter(2, refId)
		.setParameter(3, authorityId)
		.executeUpdate();
	}
}
